//
//  GuideViewController.m
//  Main
//
//  Created by wangbaoping on 2022/4/22.
//

#import "GuideVc.h"
#import "common/BaseTbc.h"
#import "PageManager.h"

@interface GuideVc ()

@property(strong, nonatomic)NSArray * images;

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;
@property (weak, nonatomic) IBOutlet UIButton *enterButton;


@end

@implementation GuideVc

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initScrollView];
    [self initPageControl];
    
}

-(void)initScrollView{
    self->_images = @[@"guide_page0",@"guide_page1",@"guide_page2",@"guide_page3"];
    self->_scrollView.contentSize = CGSizeMake(kScreen_width * self->_images.count, kScreen_height);
    self->_scrollView.bounces = NO;
    for (int i = 0; i < self->_images.count; i ++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * kScreen_width, -kStatusBar_height, kScreen_width, kScreen_height+kStatusBar_height+kNavigationBar_height)];
        imageView.contentMode = UIViewContentModeScaleToFill;
        imageView.image = [UIImage imageNamed:self->_images[i]];
        [self->_scrollView addSubview:imageView];
    }
}

-(void)initPageControl{
    self->_pageControl.numberOfPages = self->_images.count;
    self->_pageControl.currentPage = 0;

}

- (IBAction)enterButtonClick:(UIButton *)sender {
    [PageManager enterHome:self.navigationController];
}


#pragma mark - scrollView Delegate
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    int cuttentIndex = (int)(scrollView.contentOffset.x + kScreen_width/2)/kScreen_width;
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int cuttentIndex = (int)(scrollView.contentOffset.x + kScreen_width/2)/kScreen_width;
    self->_pageControl.currentPage = cuttentIndex;
    if (cuttentIndex == self->_images.count - 1) {
        self->_enterButton.hidden = false;
    }else{
        self->_enterButton.hidden = true;
    }
    
}



@end
